<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>批量导入商品</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
</head>
<style>
    .box{
        text-align: center;
        margin: auto;
        margin-top: 20px;
    }
</style>
<body>
<a style="margin-left: 20px" onmouseover="show_tips(this)"><i class="layui-icon">&#xe607;</i>帮助</a>
<div style="width: 100%;height: 100%">
    <div class="box">
        <button class="layui-btn" id="exportPPUser">下载excel模板</button>
    </div>
    <div class="box">
        <button class="layui-btn" id="uploadexcel">导入excel文件</button>
    </div>
</div>

</body>
<script>
    var $ = layui.$;
    var upload = layui.upload;
    function show_tips(th) {
        layer.tips(
            "先下载excel模板，打开模板，在模板中根据表头信息填写商品信息，请勿增删表格的表头，其中英语信息为选填，最后将填写完整的excel进行批量导入即可。图片，规格，详情通过编辑添加。",
            th,
            {tips:[3, '#3595CC'],time:5000}
            );
    }

    // $("#exportPPUser").on("click",function () {
    //     window.open("/goods/exportExcel");
    // });

    //下载租用号码模板
    $("#exportPPUser").on("click",function () {
        window.location.href="importGoodsTemplates.xls";
    });

    //上传excel文件
    var uploadInst = upload.render({
        elem: '#uploadexcel',
        url: '/goods/importGoodsExcel', //改成您自己的上传接口
        done: function (res) {
            if (res.code == 200) {
                layer.msg("导入成功！",);
                setTimeout(function(){
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭弹出层
                    // parent.location.reload();//重新加载父页面表格
                }, 2000);
            }
            else {
                layer.alert(res.data, {
                    icon: 2,
                    skin: 'layer-ext-demo'
                })
                var  index = layui.layer.load();
                layer.close(index);
            }
        },
        error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }
        ,accept:'file'
    });
</script>
</html>